package leetcode.链表;

/**
 * Created with IntelliJ IDEA.
 * Description: 使用快慢指针.
 * User: 小峰
 * Date: 2019-10-25
 * Time: 11:16
 * Url: https://leetcode-cn.com/problems/linked-list-cycle/
 */
public class _141_环形链表 {
    public boolean hasCycle(ListNode head) {
        if(head==null) {
            return false;
        }
        ListNode slow = head;
        ListNode first = head.next;
        while (first !=null && first.next!=null) {
            slow = slow.next;
            first = first.next.next;
            if (slow == first) {
                return true;
            }
        }
        return false;
    }
}
